<template>
      <h2 style="text-align: center;">登录</h2>
      <table>
          <tr>
            <td>账号</td>
            <td>
                <input type="text" placeholder="请输入账号" v-model="UserInfo.Uname"/>
            </td>
          </tr>
          <tr>
            <td>密码</td>
            <td>
                <input type="password" placeholder="请输入密码" v-model="UserInfo.Upwd" />
            </td>
          </tr>
          <tr>
            <td colspan="2" style="text-align: center;">
                <button @click="login()">登录</button>
            </td>
          </tr>
      </table>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import axios from 'axios';

const UserInfo = ref({
    Uname:"",
    Upwd:"",
})

const login = ()=>{
    if(UserInfo.value.Uname=="")
    {
         alert('请输入账号')
         return;
    }
    if(UserInfo.value.Upwd=="")
    {
         alert('请输入密码')
         return;
    }
    axios.get("https://localhost:44331/api/Users/ShowUserLoginInfo",{
        params:{
            Uname:UserInfo.value.Uname,
            Upwd:UserInfo.value.Upwd
        }
    }).then(res=>{
        if(res.data==1)
        {
            alert('登录成功')
            
        }
        else if(res.data==0)
        {
            alert('密码错误!')
            return;
        } else
        {
            alert('账号不存在!')
            return;
        }
        
    }).catch(err=>{
        console.log(err);
    })
}
</script>